package com.parse.starter;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import android.app.Application;
import android.graphics.Bitmap;

import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseAnalytics;
import com.parse.ParseInstallation;
import com.parse.ParseUser;
import com.parse.PushService;
import com.parse.bean.ExeInfo;
import com.parse.bean.PicInfo;
import com.parse.contract.ApplicationSource;

public class ParseApplication extends Application {

	final private ExeInfo info = new ExeInfo();
	final Map<String, PicInfo> bitMap = new HashMap<String, PicInfo>();
	final Set<String> keys = new HashSet<String>();


	// final private List<ProduceInfo> pInfos = new ArrayList<ProduceInfo>()

	@Override
	public void onCreate() {
		super.onCreate();

		// Add your initialization code here
		Parse.initialize(this,//
				ApplicationSource.APP_ID,//
				ApplicationSource.CLIENT_ID);

		ParseUser.enableAutomaticUser();
		ParseACL defaultACL = new ParseACL();

		// If you would like all objects to be private by default, remove this
		// line.
		defaultACL.setPublicReadAccess(true);

		ParseACL.setDefaultACL(defaultACL, true);

		PushService.setDefaultPushCallback(this, ParseStarterProjectActivity.class);
		ParseInstallation.getCurrentInstallation().saveInBackground();
		

	}

	public ExeInfo getInfo() {
		return info;
	}

	/**
	 * 判斷是否要下載
	 * 
	 * @param url
	 * @return
	 */
	public boolean need2Download(String url) {
		if (url == null || url.equals("")) {
			return false;
		}
		if (this.keys.contains(url)) {
			return false;

		} else {
			return true;
		}
	}

	/**
	 * 放置於Goal variable
	 * 
	 * @param objectId
	 * @param url
	 * @param bitmap
	 */
	public void putBitmap(String objectId, String url, Bitmap bitmap) {

		if (this.need2Download(url)) {
			final PicInfo info = new PicInfo();
			info.setBitmap(bitmap);
			this.bitMap.put(objectId, info);
			this.keys.add(url);

		} else {
			// 資料已經存在不用在存了
		}

	}

	public PicInfo get(String object) {
		return

		this.bitMap.get(object);
	}


}
